import {ListConstants} from './constants';

export function List(state = {list:{},one:{}}, action) {
  switch (action.type) {
    case ListConstants.GETALL_REQUEST:
      return {
        ...state,
        status: "loading"
      };

    case ListConstants.GETALL_SUCCESS:
      return {
        ...state,
        list: action.list,
        status: "list_success"
      };
    case ListConstants.GETALL_FAILURE:
      return {
        ...state,
        status: "list_failed"
      };
    case ListConstants.GETONE_REQUEST:
      return {
        ...state,
        status: "loading"
      }
    case ListConstants.GETONE_SUCCESS:
      return {
        ...state,
        one: action.one,
        status: "one_success"
      };
    case ListConstants.GETONE_FAILURE:
      return {
        ...state,
        status: "one_failed"
      };

    case ListConstants.CLEAR_LIST:
      return {
        ...state,
        list: null
      };
    default:
      return state
  }
}